<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/17 0017
  Time: 10:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    DiskFileItemFactory dfif = new DiskFileItemFactory();
    dfif.setRepository(new File("C:\\Users\\maTengLong\\Desktop\\shangchuan"));
    dfif.setDefaultCharset("utf-8");
    ServletFileUpload upload = new ServletFileUpload(dfif);
    List<FileItem> fileItems = upload.parseRequest(request);
    for(FileItem fileItem:fileItems){
        if(fileItem.isFormField()){
        }else{
            String name = fileItem.getName();
            //IE浏览器
            if(name.lastIndexOf("\\")>-1){
                name = name.substring(name.lastIndexOf("\\")+1);
            //chrome浏览器
            /*if(name.lastIndexOf("/")>-1){
                name = name.substring(name.lastIndexOf("/")+1);*/
            }
            System.out.println(name);
            fileItem.write(new File(application.getRealPath("/tuji")+"/"+name));
        }
    }
    response.sendRedirect("list.jsp");

%>